// 用户管理模块接口
import request from "@/utils/request";
import { UserResponseData, User, AllRoleListResponseData, SetRoleData, DelUserData } from "./type";

enum API {
  ALLUSER_URL = "/admin/acl/user",
  ADDUSER_URL = "/admin/acl/user/save",
  UPDATEUSER_URL = "/admin/acl/user/update",
  ALLROLE_URL = "/admin/acl/user/roleList",
  SETROLE_URL = "/admin/acl/user/setRole",
  DELUSER_URL = "/admin/acl/user/remove"
}

// 获取用户列表信息
export const reqUserList = (page: number, limit: number, searchName: string) =>
  request.get<any, UserResponseData>((API.ALLUSER_URL + `?page=${page}&limit=${limit}&searchName=${searchName}`) as any);
// 修改用户列表
export const reqAddUser = (data: User) => {
  if (data.id) {
    // 更新用户信息
    return request.put<any, any>(API.UPDATEUSER_URL, data);
  } else {
    // 新增用户
    return request.post<any, any>(API.ADDUSER_URL, data);
  }
};
// 获取用户的角色列表和全部角色信息
export const reqRoleList = (id: number) => request.get<any, AllRoleListResponseData>(API.ALLROLE_URL + `?id=${id}`);
// 更新用户角色列表
export const reqSetRole = (data: SetRoleData) => request.post<any, any>(API.SETROLE_URL, data);
// 删除用户 单个或批量
export const reqDelUser = (data: DelUserData) => request.post<any, any>(API.DELUSER_URL, data);
